import {subscribe, View, view, binder} from "adajs";
import StatusService from "./state.js";
import dispatcher from "./../lib/socket";

@view({
	className: "status",
	template: "./template.html",
	style: "./style.scss",
	dataset: {
		service: StatusService
	}
})
class Status extends View {
	oncreated() {
		dispatcher.observe(this);
	}

	@subscribe("status")
	status(data) {
		this.commit("reset", data);
	}

	@binder("run")
	run({e}) {
		if (!e.target.classList.contains("diable")) {
			let val = this.finder("input").getElement().value;
			if (val) {
				this.commit("run", val);
				this.dispatchEvent("startask");
			}
		}
	}
}

export default Status;